// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  try {
    const result = await cloud.openapi.subscribeMessage.send({
      "touser": event.openId, //要推送给哪个用户
      "page": 'pages/index/index', //要跳转的页面
      "lang": 'zh_CN',
      "data": { //推送的内容
        thing1: {
          "value": event.name
        },
        thing2: {
          "value": '2021年06月24日'
        },
        thing3: {
          "value": '曲靖大马坊村'
        }
      },
      "templateId": 'HKBw3ECWROLxKW-JxD8lWhq-ouWhtTZfVRb7IxJb_CY', //模板id
      "miniprogramState": 'developer'
    })
    return result
  } catch (err) {
    return err
  }
}